﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.SIESystemManager.Calculate
{
    public class C_D41
    {
        public double GetD41(DataRow[] dr1, DataRow[] dr2,string Routing)
        {
            double TclearHour = 0;//打包工时
            double TDBHour = 0;//打包工时
            double TD41 = 0, Tw1 = 0, Tw2 = 0, Td1 = 0, Td2 = 0,
                TWorkStation1 = 0, TWorkStation2 = 0, TWorkStation3 = 0,
                T41a = 0, T41b = 0, T41c = 0;
            double TD41_Coefficient_Width_W1 = 0;//D41_系数阔度W1
            double TD41_Coefficient_Width_W2 = 0;//D41_系数阔度W2
            double TD41_Coefficient_Depth_D1 = 0;//D41_系数深度D1
            double TD41_Coefficient_Depth_D2 = 0;//D41_系数深度D2
            double TD41_Coefficient_Angle_Z = 0;//D41_系数转角Z
            double TD41_Installation_Of_Door_Tape = 0;//D41_装趟门胶条
            double TD41_L_Type_Tape = 0;//D41_装L型胶条
            double TD41_Plate_Thickness_Cut_Slope = 0;//D41_板厚切斜边
            double TD41_Shape_Of_Plate_Gong = 0;//D41_板面锣外形
            double TD41_Slab_Bevel_Angle = 0;//D41_板面切斜角
            double TD41_Gong_Plane_Blind_Groove = 0;//D41_锣平面盲槽
            double TD41_Gong_Lock_Slot_Side = 0;//D41_锣锁片槽侧
            double TD41_Gong_Lock_Plate_Groove_Flat = 0;//D41_锣锁片槽平
            double TD41_Drilling_Vertical_Blind_Hole = 0;//D41_钻垂直盲孔
            double TD41_Drilling_Vertical_Through_Hole = 0;//D41_钻垂直通孔
            double TD41_Drilling_Horizontal_Side_Hole = 0;//D41_钻水平侧孔
            double TD41_Copper_Head_Plug = 0;//D41_打铜头胶塞
            double TD41_Twisted_Tooth_Nut = 0;//D41_拧带齿螺母
            double TD41_General_Label = 0;//D41_贴通用标签
            double TD41_Slot_Side_Scrubbing = 0;//D41_槽侧边擦色
            double TD41_Lock_Tapping_Screw = 0;//D41_锁自攻螺丝
            double TD41_Paste_White_Adhesive_Paper = 0;//D41_贴白色胶纸
            double TD41_LOGO = 0;//D41_贴美时LOGO
            double TD41_Double_Sided_Adhesive_Paper = 0;//D41_贴双面胶纸
            double TD41_Mounting_Screen_Hanging_Code = 0;//D41_装屏风挂码
            double TD41_Decorative_Hole_Cover = 0;//D41_装装饰孔盖
            double TD41_Fittings_For_Door_Tongue = 0;//装门舌配件

            double WD41_Plate_Thickness_Cut_Slope = 0;//D41_板厚切斜边-单位工时
            double AD41_Plate_Thickness_Cut_Slope = 0;//D41_板厚切斜边-附加工时
            double WD41_Shape_Of_Plate_Gong = 0;//D41_板面锣外形-单位工时
            double AD41_Shape_Of_Plate_Gong = 0;//D41_板面锣外形-附加工时
            double WD41_Slab_Bevel_Angle = 0;//D41_板面切斜角-单位工时
            double AD41_Slab_Bevel_Angle = 0;//D41_板面切斜角-附加工时
            double WD41_Gong_Lock_Slot_Side = 0;//D41_锣锁片槽侧-单位工时
            double WD41_Gong_Lock_Plate_Groove_Flat = 0;//D41_锣锁片槽平-单位工时
            double AD41_Gong_Lock_Slot_Side = 0;//D41_锣锁片槽侧-附加工时
            double AD41_Gong_Lock_Plate_Groove_Flat = 0;//D41_锣锁片槽平-附加工时
            double WD41_Drilling_Vertical_Through_Hole = 0;//D41_钻垂直通孔-单位工时
            double AD41_Drilling_Vertical_Through_Hole = 0;//D41_钻垂直通孔-附加工时
            double WD41_Copper_Head_Plug = 0;//D41_打铜头胶塞-单位工时
            double WD41_Twisted_Tooth_Nut = 0;//D41_拧带齿螺母-单位工时
            double WD41_General_Label = 0;//D41_贴通用标签-单位工时
            double AD41_Copper_Head_Plug = 0;//D41_打铜头胶塞-附加工时
            double AD41_Twisted_Tooth_Nut = 0;//D41_拧带齿螺母-附加工时
            double AD41_General_Label = 0;//D41_贴通用标签-附加工时
            double WD41_Lock_Tapping_Screw = 0;//D41_锁自攻螺丝-单位工时
            double WD41_Paste_White_Adhesive_Paper = 0;//D41_贴白色胶纸-单位工时
            double WD41_LOGO = 0;//D41_贴美时LOGO-单位工时
            double WD41_Double_Sided_Adhesive_Paper = 0;//D41_贴双面胶纸-单位工时
            double WD41_Mounting_Screen_Hanging_Code = 0;//D41_装屏风挂码-单位工时
            double WD41_Decorative_Hole_Cover = 0;//D41_装装饰孔盖-单位工时
            double AD41_Lock_Tapping_Screw = 0;//D41_锁自攻螺丝-附加工时
            double AD41_Paste_White_Adhesive_Paper = 0;//D41_贴白色胶纸-附加工时
            double AD41_LOGO = 0;//D41_贴美时LOGO-附加工时
            double AD41_Double_Sided_Adhesive_Paper = 0;//D41_贴双面胶纸-附加工时
            double AD41_Mounting_Screen_Hanging_Code = 0;//D41_装屏风挂码-附加工时
            double AD41_Decorative_Hole_Cover = 0;//D41_装装饰孔盖-附加工时         
            double WD41_Fittings_For_Door_Tongue = 0;//装门舌配件-单位工时
            double AD41_Fittings_For_Door_Tongue = 0;//装门舌配件-附加工时

            //获取数据库每个工序动作的单位工时和附加工时
            foreach (var drHours in dr2)
            {
                switch (drHours["OPERATIONAL_NAME"].ToString())
                {
                    case "板厚切斜边":
                        WD41_Plate_Thickness_Cut_Slope = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Plate_Thickness_Cut_Slope = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "板面锣外形":
                        WD41_Shape_Of_Plate_Gong = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Shape_Of_Plate_Gong = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "板面切斜角":
                        WD41_Slab_Bevel_Angle = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Slab_Bevel_Angle = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "锣锁片槽侧":
                        WD41_Gong_Lock_Slot_Side = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Gong_Lock_Slot_Side = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "锣锁片槽平":
                        WD41_Gong_Lock_Plate_Groove_Flat = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Gong_Lock_Plate_Groove_Flat = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "M钻垂直通孔":
                        WD41_Drilling_Vertical_Through_Hole = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Drilling_Vertical_Through_Hole = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "打铜头胶塞":
                        WD41_Copper_Head_Plug = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Copper_Head_Plug = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "拧带齿螺母":
                        WD41_Twisted_Tooth_Nut = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Twisted_Tooth_Nut = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "贴通用标签":
                        WD41_General_Label = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_General_Label = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "锁自攻螺丝":
                        WD41_Lock_Tapping_Screw = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Lock_Tapping_Screw = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "贴白色胶纸":
                        WD41_Paste_White_Adhesive_Paper = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Paste_White_Adhesive_Paper = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "贴美时LOGO":
                        WD41_LOGO = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_LOGO = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "贴双面胶纸":
                        WD41_Double_Sided_Adhesive_Paper = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Double_Sided_Adhesive_Paper = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装屏风挂码":
                        WD41_Mounting_Screen_Hanging_Code = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Mounting_Screen_Hanging_Code = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装装饰孔盖":
                        WD41_Decorative_Hole_Cover = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Decorative_Hole_Cover = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装门舌配件":
                        WD41_Fittings_For_Door_Tongue = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD41_Fittings_For_Door_Tongue = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                }
            }
            foreach (var drData in dr1)
            {
                Tw1 = double.Parse(string.IsNullOrEmpty(drData["Width_1"].ToString().Replace("*", "")) ? "0" : drData["Width_1"].ToString().Replace("*", ""));//W1
                Tw2 = double.Parse(string.IsNullOrEmpty(drData["Width_2"].ToString().Replace("*", "")) ? "0" : drData["Width_2"].ToString().Replace("*", ""));//w2
                Td1 = double.Parse(string.IsNullOrEmpty(drData["Depth_1"].ToString().Replace("*", "")) ? "0" : drData["Depth_1"].ToString().Replace("*", ""));//d1
                Td2 = double.Parse(string.IsNullOrEmpty(drData["Depth_2"].ToString().Replace("*", "")) ? "0" : drData["Depth_2"].ToString().Replace("*", ""));//d2

                TD41_Coefficient_Width_W1 = double.Parse(string.IsNullOrEmpty(drData["D41_Coefficient_Width_W1"].ToString()) ? "0" : drData["D41_Coefficient_Width_W1"].ToString());//D41_系数阔度W1
                TD41_Coefficient_Width_W2 = double.Parse(string.IsNullOrEmpty(drData["D41_Coefficient_Width_W2"].ToString()) ? "0" : drData["D41_Coefficient_Width_W2"].ToString());//D41_系数阔度W2
                TD41_Coefficient_Depth_D1 = double.Parse(string.IsNullOrEmpty(drData["D41_Coefficient_Depth_D1"].ToString()) ? "0" : drData["D41_Coefficient_Depth_D1"].ToString());//D41_系数深度D1
                TD41_Coefficient_Depth_D2 = double.Parse(string.IsNullOrEmpty(drData["D41_Coefficient_Depth_D2"].ToString()) ? "0" : drData["D41_Coefficient_Depth_D2"].ToString());//D41_系数深度D2
                TD41_Coefficient_Angle_Z = double.Parse(string.IsNullOrEmpty(drData["D41_Coefficient_Angle_Z"].ToString()) ? "0" : drData["D41_Coefficient_Angle_Z"].ToString());//D41_系数转角Z
                TD41_Installation_Of_Door_Tape = double.Parse(string.IsNullOrEmpty(drData["D41_Installation_Of_Door_Tape"].ToString()) ? "0" : drData["D41_Installation_Of_Door_Tape"].ToString());//D41_装趟门胶条
                TD41_L_Type_Tape = double.Parse(string.IsNullOrEmpty(drData["D41_L_Type_Tape"].ToString()) ? "0" : drData["D41_L_Type_Tape"].ToString());//D41_装L型胶条
                TD41_Plate_Thickness_Cut_Slope = double.Parse(string.IsNullOrEmpty(drData["D41_Plate_Thickness_Cut_Slope"].ToString()) ? "0" : drData["D41_Plate_Thickness_Cut_Slope"].ToString());//D41_板厚切斜边
                TD41_Shape_Of_Plate_Gong = double.Parse(string.IsNullOrEmpty(drData["D41_Shape_Of_Plate_Gong"].ToString()) ? "0" : drData["D41_Shape_Of_Plate_Gong"].ToString());//D41_板面锣外形
                TD41_Slab_Bevel_Angle = double.Parse(string.IsNullOrEmpty(drData["D41_Slab_Bevel_Angle"].ToString()) ? "0" : drData["D41_Slab_Bevel_Angle"].ToString());//D41_板面切斜角
                TD41_Gong_Plane_Blind_Groove = double.Parse(string.IsNullOrEmpty(drData["D41_Gong_Plane_Blind_Groove"].ToString()) ? "0" : drData["D41_Gong_Plane_Blind_Groove"].ToString());//D41_锣平面盲槽
                TD41_Gong_Lock_Slot_Side = double.Parse(string.IsNullOrEmpty(drData["D41_Gong_Lock_Slot_Side"].ToString()) ? "0" : drData["D41_Gong_Lock_Slot_Side"].ToString());//D41_锣锁片槽侧
                TD41_Gong_Lock_Plate_Groove_Flat = double.Parse(string.IsNullOrEmpty(drData["D41_Gong_Lock_Plate_Groove_Flat"].ToString()) ? "0" : drData["D41_Gong_Lock_Plate_Groove_Flat"].ToString());//D41_锣锁片槽平
                TD41_Drilling_Vertical_Blind_Hole = double.Parse(string.IsNullOrEmpty(drData["D41_Drilling_Vertical_Blind_Hole"].ToString()) ? "0" : drData["D41_Drilling_Vertical_Blind_Hole"].ToString());//D41_钻垂直盲孔
                TD41_Drilling_Vertical_Through_Hole = double.Parse(string.IsNullOrEmpty(drData["D41_Drilling_Vertical_Through_Hole"].ToString()) ? "0" : drData["D41_Drilling_Vertical_Through_Hole"].ToString());//D41_钻垂直通孔
                TD41_Drilling_Horizontal_Side_Hole = double.Parse(string.IsNullOrEmpty(drData["D41_Drilling_Horizontal_Side_Hole"].ToString()) ? "0" : drData["D41_Drilling_Horizontal_Side_Hole"].ToString());//D41_钻水平侧孔
                TD41_Copper_Head_Plug = double.Parse(string.IsNullOrEmpty(drData["D41_Copper_Head_Plug"].ToString()) ? "0" : drData["D41_Copper_Head_Plug"].ToString());//D41_打铜头胶塞
                TD41_Twisted_Tooth_Nut = double.Parse(string.IsNullOrEmpty(drData["D41_Twisted_Tooth_Nut"].ToString()) ? "0" : drData["D41_Twisted_Tooth_Nut"].ToString());//D41_拧带齿螺母
                TD41_General_Label = double.Parse(string.IsNullOrEmpty(drData["D41_General_Label"].ToString()) ? "0" : drData["D41_General_Label"].ToString());//D41_贴通用标签
                TD41_Slot_Side_Scrubbing = double.Parse(string.IsNullOrEmpty(drData["D41_Slot_Side_Scrubbing"].ToString()) ? "0" : drData["D41_Slot_Side_Scrubbing"].ToString());//D41_槽侧边擦色
                TD41_Lock_Tapping_Screw = double.Parse(string.IsNullOrEmpty(drData["D41_Lock_Tapping_Screw"].ToString()) ? "0" : drData["D41_Lock_Tapping_Screw"].ToString());//D41_锁自攻螺丝
                TD41_Paste_White_Adhesive_Paper = double.Parse(string.IsNullOrEmpty(drData["D41_Paste_White_Adhesive_Paper"].ToString()) ? "0" : drData["D41_Paste_White_Adhesive_Paper"].ToString());//D41_贴白色胶纸
                TD41_LOGO = double.Parse(string.IsNullOrEmpty(drData["D41_LOGO"].ToString()) ? "0" : drData["D41_LOGO"].ToString());//D41_贴美时LOGO
                TD41_Double_Sided_Adhesive_Paper = double.Parse(string.IsNullOrEmpty(drData["D41_Double_Sided_Adhesive_Paper"].ToString()) ? "0" : drData["D41_Double_Sided_Adhesive_Paper"].ToString());//D41_贴双面胶纸
                TD41_Mounting_Screen_Hanging_Code = double.Parse(string.IsNullOrEmpty(drData["D41_Mounting_Screen_Hanging_Code"].ToString()) ? "0" : drData["D41_Mounting_Screen_Hanging_Code"].ToString());//D41_装屏风挂码
                TD41_Decorative_Hole_Cover = double.Parse(string.IsNullOrEmpty(drData["D41_Decorative_Hole_Cover"].ToString()) ? "0" : drData["D41_Decorative_Hole_Cover"].ToString());//D41_装装饰孔盖
                TD41_Fittings_For_Door_Tongue = double.Parse(string.IsNullOrEmpty(drData["D41_Fittings_For_Door_Tongue"].ToString()) ? "0" : drData["D41_Fittings_For_Door_Tongue"].ToString());//D41_装门舌配件
            }
            //清洗时间
            if (TD41_Coefficient_Width_W1 != 0 || TD41_Coefficient_Width_W2 != 0 || TD41_Coefficient_Depth_D1 != 0 || TD41_Coefficient_Depth_D2 != 0 ||
                TD41_Coefficient_Angle_Z != 0 || TD41_Installation_Of_Door_Tape != 0 || TD41_L_Type_Tape != 0 || TD41_Plate_Thickness_Cut_Slope != 0 ||
                TD41_Shape_Of_Plate_Gong != 0 || TD41_Slab_Bevel_Angle != 0 || TD41_Gong_Plane_Blind_Groove != 0 || TD41_Gong_Lock_Slot_Side != 0 ||
                TD41_Gong_Lock_Plate_Groove_Flat != 0 || TD41_Drilling_Vertical_Blind_Hole != 0 || TD41_Drilling_Vertical_Through_Hole != 0 ||
                TD41_Drilling_Horizontal_Side_Hole != 0 || TD41_Copper_Head_Plug != 0 || TD41_Twisted_Tooth_Nut != 0 || TD41_General_Label != 0 ||
                TD41_Slot_Side_Scrubbing != 0 || TD41_Lock_Tapping_Screw != 0 || TD41_Paste_White_Adhesive_Paper != 0 || TD41_LOGO != 0 ||
                TD41_Double_Sided_Adhesive_Paper != 0 || TD41_Mounting_Screen_Hanging_Code != 0 || TD41_Decorative_Hole_Cover != 0 || TD41_Fittings_For_Door_Tongue != 0)
            {
                /*工艺路线包含D34 D37其中一个或两个，则不计算清洗时间和打包时间
                 符合上面条件时间，工时只计算T41a*/
                if (!Routing.Contains("D34") && !Routing.Contains("D37"))
                {
                    TclearHour = (0.000058 * Tw1 * Tw2 * 2) + 10;

                    TDBHour = 30;//打包工时
                }

            }

            //计算工位1
            if (TD41_Coefficient_Width_W1 != 0 || TD41_Coefficient_Width_W2 != 0 || TD41_Coefficient_Depth_D1 != 0 ||
                TD41_Coefficient_Depth_D2 != 0 || TD41_Coefficient_Angle_Z != 0 || TD41_Installation_Of_Door_Tape != 0 ||
                TD41_L_Type_Tape != 0 || TD41_Plate_Thickness_Cut_Slope != 0 || TD41_Shape_Of_Plate_Gong != 0 ||
                TD41_Slab_Bevel_Angle != 0 || TD41_Gong_Plane_Blind_Groove != 0 || TD41_Gong_Lock_Slot_Side != 0 ||
                TD41_Gong_Lock_Plate_Groove_Flat != 0 || TD41_Drilling_Vertical_Blind_Hole != 0 || TD41_Drilling_Vertical_Through_Hole != 0 ||
                TD41_Drilling_Horizontal_Side_Hole != 0 || TD41_Copper_Head_Plug != 0 || TD41_Twisted_Tooth_Nut != 0)
            {
                //计算W1 W2 D1 D2 Z
                if (TD41_Coefficient_Width_W1 != 0 || TD41_Coefficient_Width_W2 != 0 || TD41_Coefficient_Depth_D1 != 0 ||
                TD41_Coefficient_Depth_D2 != 0 || TD41_Coefficient_Angle_Z != 0)
                {
                    T41a = 40 + 0.015 * (TD41_Coefficient_Width_W1 * Tw1 + TD41_Coefficient_Width_W2 * Tw2 +
                        TD41_Coefficient_Depth_D1 * Td1 + TD41_Coefficient_Depth_D2 * Td2 +
                        TD41_Coefficient_Angle_Z * ((Tw1 + Tw2 - (Td1 + Td2))));
                }
                //计算装趟门胶条
                if (TD41_Installation_Of_Door_Tape != 0)
                {
                    if (NumMAX(Tw1, Tw2) < 1000)
                    {
                        T41a = T41a + 50 + 15 * TD41_Installation_Of_Door_Tape;
                    }
                    else
                    {
                        T41a = T41a + 55 + 20 * TD41_Installation_Of_Door_Tape;
                    }
                }
                //计算装L型胶条
                if (TD41_L_Type_Tape != 0)
                {
                    if (NumMAX(Tw1, Tw2) < 1000)
                    {
                        T41a = T41a + 50 + 15 * TD41_L_Type_Tape;
                    }
                    else
                    {
                        T41a = T41a + 55 + 20 * TD41_L_Type_Tape;
                    }
                }
                //计算板厚切斜边
                if (TD41_Plate_Thickness_Cut_Slope != 0)
                {
                    T41a = T41a + TD41_Plate_Thickness_Cut_Slope * WD41_Plate_Thickness_Cut_Slope + AD41_Plate_Thickness_Cut_Slope;
                }
                //计算板面锣外形
                if (TD41_Shape_Of_Plate_Gong != 0)
                {
                    T41a = T41a + TD41_Shape_Of_Plate_Gong * WD41_Shape_Of_Plate_Gong + AD41_Shape_Of_Plate_Gong;
                }
                //计算板面切斜角
                if (TD41_Slab_Bevel_Angle != 0)
                {
                    T41a = T41a + TD41_Slab_Bevel_Angle * WD41_Slab_Bevel_Angle + AD41_Slab_Bevel_Angle;
                }
                //计算锣平面盲槽
                if (TD41_Gong_Plane_Blind_Groove != 0)
                {
                    if (NumMAX(Tw1, Tw2) < 1500)
                    {
                        T41a = T41a + 8 + 50 * TD41_Gong_Plane_Blind_Groove;
                    }
                    else
                    {
                        T41a = T41a + 8 + 70 * TD41_Gong_Plane_Blind_Groove;
                    }
                }
                //计算锣锁片槽侧
                if (TD41_Gong_Lock_Slot_Side != 0)
                {
                    T41a = T41a + TD41_Gong_Lock_Slot_Side * WD41_Gong_Lock_Slot_Side + AD41_Gong_Lock_Slot_Side;
                }
                //计算锣锁片槽平
                if (TD41_Gong_Lock_Plate_Groove_Flat != 0)
                {
                    T41a = T41a + TD41_Gong_Lock_Plate_Groove_Flat * WD41_Gong_Lock_Plate_Groove_Flat + AD41_Gong_Lock_Plate_Groove_Flat;
                }
                //计算钻垂直盲孔
                if (TD41_Drilling_Vertical_Blind_Hole != 0)
                {
                    if (Tw1 > 1300 && Tw2 > 1300)//同时大于1300
                    {
                        T41a = T41a + 30 + 10 + 30 * TD41_Drilling_Vertical_Blind_Hole;
                    }
                    else
                    {
                        T41a = T41a + 5 + 10 + 5 * TD41_Drilling_Vertical_Blind_Hole;
                    }
                }
                //计算钻垂直通孔
                if (TD41_Drilling_Vertical_Through_Hole != 0)
                {
                    T41a = T41a + TD41_Drilling_Vertical_Through_Hole * WD41_Drilling_Vertical_Through_Hole + AD41_Drilling_Vertical_Through_Hole;
                }
                //计算钻水平侧孔
                if (TD41_Drilling_Horizontal_Side_Hole != 0)
                {
                    if (Tw1 > 1300 && Tw2 > 1300)//同时大于1300
                    {
                        T41a = T41a + 30 + 10 + 30 * TD41_Drilling_Horizontal_Side_Hole;
                    }
                    else
                    {
                        T41a = T41a + 5 + 10 + 5 * TD41_Drilling_Horizontal_Side_Hole;
                    }
                }
                //计算打铜头胶塞
                if (TD41_Copper_Head_Plug != 0)
                {
                    T41a = T41a + TD41_Copper_Head_Plug * WD41_Copper_Head_Plug + AD41_Copper_Head_Plug;
                }
                //计算拧带齿螺母
                if (TD41_Twisted_Tooth_Nut != 0)
                {
                    T41a = T41a + TD41_Twisted_Tooth_Nut * WD41_Twisted_Tooth_Nut + AD41_Twisted_Tooth_Nut;
                }
                //计算装门舌配件
                if (TD41_Fittings_For_Door_Tongue != 0)
                {
                    T41a = T41a + TD41_Fittings_For_Door_Tongue * WD41_Fittings_For_Door_Tongue + AD41_Fittings_For_Door_Tongue;
                }
            }
          
            //计算贴通用标签
            if (TD41_General_Label != 0)
            {
                T41b = T41b + TD41_General_Label * WD41_General_Label + AD41_General_Label;
            }
            //计算槽侧边擦色
            if (TD41_Slot_Side_Scrubbing != 0)
            {
                T41b = T41b + 120 * TD41_Slot_Side_Scrubbing + 0;
            }
          
         

            //计算锁自攻螺丝
            if (TD41_Lock_Tapping_Screw != 0)
            {
                T41c = T41c + TD41_Lock_Tapping_Screw * WD41_Lock_Tapping_Screw + AD41_Lock_Tapping_Screw;
            }
            //计算贴白色胶纸
            if (TD41_Paste_White_Adhesive_Paper != 0)
            {
                T41c = T41c + TD41_Paste_White_Adhesive_Paper * WD41_Paste_White_Adhesive_Paper + AD41_Paste_White_Adhesive_Paper;
            }
            //计算贴美时LOGO
            if (TD41_LOGO != 0)
            {
                T41c = T41c + TD41_LOGO * WD41_LOGO + AD41_LOGO;
            }
            //计算贴双面胶纸
            if (TD41_Double_Sided_Adhesive_Paper != 0)
            {
                T41c = T41c + TD41_Double_Sided_Adhesive_Paper * WD41_Double_Sided_Adhesive_Paper + AD41_Double_Sided_Adhesive_Paper;
            }
            //计算装屏风挂码
            if (TD41_Mounting_Screen_Hanging_Code != 0)
            {
                T41c = T41c + TD41_Mounting_Screen_Hanging_Code * WD41_Mounting_Screen_Hanging_Code + AD41_Mounting_Screen_Hanging_Code;
            }
            //计算装装饰孔盖
            if (TD41_Decorative_Hole_Cover != 0)
            {
                T41c = T41c + TD41_Decorative_Hole_Cover * WD41_Decorative_Hole_Cover + AD41_Decorative_Hole_Cover;
            }
         
            //计算工位1工时
            TWorkStation1 = T41a;
            //计算工位2工时
            TWorkStation2 = T41b + TclearHour;
            //计算工位3工时
            TWorkStation3 = T41c + TDBHour;

            //Total 工时
            if (!Routing.Contains("D34") && !Routing.Contains("D37"))
            {
                TD41 = TWorkStation1 + NumMAX(TWorkStation2, TWorkStation3) * 2;
            }
            else
            {
                TD41 = TWorkStation1;
            }
            return TD41;
        }
        private static double NumMAX(double Tw1, double Tw2)
        {
            if (Tw1 > Tw2)
            {
                return Tw1;
            }
            return Tw2;
        }
       

    }
}

